package com.tech.process

import com.alibaba.fastjson.JSON
import com.tech.config.ApplicationConfig
import org.apache.kudu.client._

import java.util
import java.util.regex.Pattern


object MsgProcess {

  @throws[KuduException]
  def main(args: Array[String]): Unit = {
    //      val json = "{\"marketingActivityProcessList\":[{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e55b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000003\",\"typeIndex\":5,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e55b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:5b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"type\":100000003,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\",\"firstRedisKey\":\"activity:optimize:first:100000003\",\"nextNode\":\"db9e9465-4824-4b75-b65c-408d40064efb,05a87492-be98-456a-a1c6-b7df001ca595,26f2bfa9-932f-4250-bc75-d9b00e129758\",\"name\":\"A/B Test\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e55b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"id\":\"5b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"processDetailRedisKey\":\"activity:optimize:process:detail:5b05245e-de73-4f1a-8fd4-0c26ec5e8838\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5db9e9465-4824-4b75-b65c-408d40064efb\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000004\",\"typeIndex\":6,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5db9e9465-4824-4b75-b65c-408d40064efb\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:db9e9465-4824-4b75-b65c-408d40064efb\",\"type\":100000004,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"5b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"firstRedisKey\":\"activity:optimize:first:100000004\",\"nextNode\":\"c59f06d2-e7e8-4a06-91c0-af34dba1cd79\",\"name\":\"A/B Test Child\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5db9e9465-4824-4b75-b65c-408d40064efb\",\"id\":\"db9e9465-4824-4b75-b65c-408d40064efb\",\"processDetailRedisKey\":\"activity:optimize:process:detail:db9e9465-4824-4b75-b65c-408d40064efb\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e505a87492-be98-456a-a1c6-b7df001ca595\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000004\",\"typeIndex\":6,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e505a87492-be98-456a-a1c6-b7df001ca595\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:05a87492-be98-456a-a1c6-b7df001ca595\",\"type\":100000004,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"5b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"firstRedisKey\":\"activity:optimize:first:100000004\",\"nextNode\":\"e774b0bc-078f-4ba2-abab-03afa8317d7c\",\"name\":\"A/B Test Child\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e505a87492-be98-456a-a1c6-b7df001ca595\",\"id\":\"05a87492-be98-456a-a1c6-b7df001ca595\",\"processDetailRedisKey\":\"activity:optimize:process:detail:05a87492-be98-456a-a1c6-b7df001ca595\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e526f2bfa9-932f-4250-bc75-d9b00e129758\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000004\",\"typeIndex\":6,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e526f2bfa9-932f-4250-bc75-d9b00e129758\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:26f2bfa9-932f-4250-bc75-d9b00e129758\",\"type\":100000004,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"5b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"firstRedisKey\":\"activity:optimize:first:100000004\",\"nextNode\":\"56608636-a5c5-42e5-b15e-47e38b0cd7be\",\"name\":\"A/B Test Child\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e526f2bfa9-932f-4250-bc75-d9b00e129758\",\"id\":\"26f2bfa9-932f-4250-bc75-d9b00e129758\",\"processDetailRedisKey\":\"activity:optimize:process:detail:26f2bfa9-932f-4250-bc75-d9b00e129758\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e55567feb6-1f88-4302-b658-82fa52c2dd86\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000007\",\"typeIndex\":8,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e55567feb6-1f88-4302-b658-82fa52c2dd86\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:5567feb6-1f88-4302-b658-82fa52c2dd86\",\"type\":100000007,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"e774b0bc-078f-4ba2-abab-03afa8317d7c\",\"firstRedisKey\":\"activity:optimize:first:100000007\",\"nextNode\":\"4135bd86-56da-4856-918c-0dba2548b034\",\"name\":\"等待\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e55567feb6-1f88-4302-b658-82fa52c2dd86\",\"id\":\"5567feb6-1f88-4302-b658-82fa52c2dd86\",\"processDetailRedisKey\":\"activity:optimize:process:detail:5567feb6-1f88-4302-b658-82fa52c2dd86\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5218e7c92-3e37-46db-907a-443d4a58d9eb\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000006\",\"typeIndex\":3,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5218e7c92-3e37-46db-907a-443d4a58d9eb\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:218e7c92-3e37-46db-907a-443d4a58d9eb\",\"type\":100000006,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"f5923792-24eb-42c0-9e07-3bf05cd88db5\",\"firstRedisKey\":\"activity:optimize:first:100000006\",\"nextNode\":\"a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\",\"name\":\"奖励\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5218e7c92-3e37-46db-907a-443d4a58d9eb\",\"id\":\"218e7c92-3e37-46db-907a-443d4a58d9eb\",\"processDetailRedisKey\":\"activity:optimize:process:detail:218e7c92-3e37-46db-907a-443d4a58d9eb\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e556608636-a5c5-42e5-b15e-47e38b0cd7be\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000006\",\"typeIndex\":7,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e556608636-a5c5-42e5-b15e-47e38b0cd7be\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:56608636-a5c5-42e5-b15e-47e38b0cd7be\",\"type\":100000006,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"26f2bfa9-932f-4250-bc75-d9b00e129758\",\"firstRedisKey\":\"activity:optimize:first:100000006\",\"nextNode\":\"58ad82d4-ac5a-4502-9198-f0683629d920\",\"name\":\"奖励\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e556608636-a5c5-42e5-b15e-47e38b0cd7be\",\"id\":\"56608636-a5c5-42e5-b15e-47e38b0cd7be\",\"processDetailRedisKey\":\"activity:optimize:process:detail:56608636-a5c5-42e5-b15e-47e38b0cd7be\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5b344117a-fc42-4c76-8891-7c2db5eea563\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000006\",\"typeIndex\":8,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5b344117a-fc42-4c76-8891-7c2db5eea563\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:b344117a-fc42-4c76-8891-7c2db5eea563\",\"type\":100000006,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"c59f06d2-e7e8-4a06-91c0-af34dba1cd79\",\"firstRedisKey\":\"activity:optimize:first:100000006\",\"nextNode\":\"b56bc348-5ca9-408a-9a50-fc72edaf3cbf\",\"name\":\"奖励\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5b344117a-fc42-4c76-8891-7c2db5eea563\",\"id\":\"b344117a-fc42-4c76-8891-7c2db5eea563\",\"processDetailRedisKey\":\"activity:optimize:process:detail:b344117a-fc42-4c76-8891-7c2db5eea563\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5eb27fb0c-504a-4225-98df-9617c5489bf3\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000001\",\"typeIndex\":10,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5eb27fb0c-504a-4225-98df-9617c5489bf3\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:eb27fb0c-504a-4225-98df-9617c5489bf3\",\"type\":100000001,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"4135bd86-56da-4856-918c-0dba2548b034\",\"firstRedisKey\":\"activity:optimize:first:100000001\",\"name\":\"结束\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5eb27fb0c-504a-4225-98df-9617c5489bf3\",\"id\":\"eb27fb0c-504a-4225-98df-9617c5489bf3\",\"processDetailRedisKey\":\"activity:optimize:process:detail:eb27fb0c-504a-4225-98df-9617c5489bf3\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e558ad82d4-ac5a-4502-9198-f0683629d920\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000001\",\"typeIndex\":8,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e558ad82d4-ac5a-4502-9198-f0683629d920\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:58ad82d4-ac5a-4502-9198-f0683629d920\",\"type\":100000001,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"56608636-a5c5-42e5-b15e-47e38b0cd7be\",\"firstRedisKey\":\"activity:optimize:first:100000001\",\"name\":\"结束\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e558ad82d4-ac5a-4502-9198-f0683629d920\",\"id\":\"58ad82d4-ac5a-4502-9198-f0683629d920\",\"processDetailRedisKey\":\"activity:optimize:process:detail:58ad82d4-ac5a-4502-9198-f0683629d920\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5b56bc348-5ca9-408a-9a50-fc72edaf3cbf\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000001\",\"typeIndex\":9,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5b56bc348-5ca9-408a-9a50-fc72edaf3cbf\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:b56bc348-5ca9-408a-9a50-fc72edaf3cbf\",\"type\":100000001,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"b344117a-fc42-4c76-8891-7c2db5eea563\",\"firstRedisKey\":\"activity:optimize:first:100000001\",\"name\":\"结束\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5b56bc348-5ca9-408a-9a50-fc72edaf3cbf\",\"id\":\"b56bc348-5ca9-408a-9a50-fc72edaf3cbf\",\"processDetailRedisKey\":\"activity:optimize:process:detail:b56bc348-5ca9-408a-9a50-fc72edaf3cbf\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e50ecffbb6-71f8-4412-8207-19042bfed4f5\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000000\",\"typeIndex\":0,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e50ecffbb6-71f8-4412-8207-19042bfed4f5\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:0ecffbb6-71f8-4412-8207-19042bfed4f5\",\"type\":100000000,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKey\":\"activity:optimize:first:100000000\",\"nextNode\":\"cbb04648-3652-4b9f-8487-44a41f4c8e5d\",\"name\":\"开始\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e50ecffbb6-71f8-4412-8207-19042bfed4f5\",\"id\":\"0ecffbb6-71f8-4412-8207-19042bfed4f5\",\"processDetailRedisKey\":\"activity:optimize:process:detail:0ecffbb6-71f8-4412-8207-19042bfed4f5\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e54135bd86-56da-4856-918c-0dba2548b034\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000008\",\"typeIndex\":9,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e54135bd86-56da-4856-918c-0dba2548b034\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:4135bd86-56da-4856-918c-0dba2548b034\",\"type\":100000008,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"5567feb6-1f88-4302-b658-82fa52c2dd86\",\"firstRedisKey\":\"activity:optimize:first:100000008\",\"nextNode\":\"eb27fb0c-504a-4225-98df-9617c5489bf3\",\"name\":\"消息\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e54135bd86-56da-4856-918c-0dba2548b034\",\"id\":\"4135bd86-56da-4856-918c-0dba2548b034\",\"processDetailRedisKey\":\"activity:optimize:process:detail:4135bd86-56da-4856-918c-0dba2548b034\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000008\",\"typeIndex\":4,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\",\"type\":100000008,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"218e7c92-3e37-46db-907a-443d4a58d9eb\",\"firstRedisKey\":\"activity:optimize:first:100000008\",\"nextNode\":\"5b05245e-de73-4f1a-8fd4-0c26ec5e8838\",\"name\":\"消息\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\",\"id\":\"a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\",\"processDetailRedisKey\":\"activity:optimize:process:detail:a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5e774b0bc-078f-4ba2-abab-03afa8317d7c\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000005\",\"typeIndex\":7,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5e774b0bc-078f-4ba2-abab-03afa8317d7c\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:e774b0bc-078f-4ba2-abab-03afa8317d7c\",\"type\":100000005,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"05a87492-be98-456a-a1c6-b7df001ca595\",\"firstRedisKey\":\"activity:optimize:first:100000005\",\"nextNode\":\"5567feb6-1f88-4302-b658-82fa52c2dd86\",\"name\":\"行为\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5e774b0bc-078f-4ba2-abab-03afa8317d7c\",\"id\":\"e774b0bc-078f-4ba2-abab-03afa8317d7c\",\"processDetailRedisKey\":\"activity:optimize:process:detail:e774b0bc-078f-4ba2-abab-03afa8317d7c\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5f5923792-24eb-42c0-9e07-3bf05cd88db5\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000005\",\"typeIndex\":2,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5f5923792-24eb-42c0-9e07-3bf05cd88db5\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:f5923792-24eb-42c0-9e07-3bf05cd88db5\",\"type\":100000005,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"cbb04648-3652-4b9f-8487-44a41f4c8e5d\",\"firstRedisKey\":\"activity:optimize:first:100000005\",\"nextNode\":\"218e7c92-3e37-46db-907a-443d4a58d9eb\",\"name\":\"行为\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5f5923792-24eb-42c0-9e07-3bf05cd88db5\",\"id\":\"f5923792-24eb-42c0-9e07-3bf05cd88db5\",\"processDetailRedisKey\":\"activity:optimize:process:detail:f5923792-24eb-42c0-9e07-3bf05cd88db5\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5c59f06d2-e7e8-4a06-91c0-af34dba1cd79\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000005\",\"typeIndex\":7,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5c59f06d2-e7e8-4a06-91c0-af34dba1cd79\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:c59f06d2-e7e8-4a06-91c0-af34dba1cd79\",\"type\":100000005,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"db9e9465-4824-4b75-b65c-408d40064efb\",\"firstRedisKey\":\"activity:optimize:first:100000005\",\"nextNode\":\"b344117a-fc42-4c76-8891-7c2db5eea563\",\"name\":\"行为\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5c59f06d2-e7e8-4a06-91c0-af34dba1cd79\",\"id\":\"c59f06d2-e7e8-4a06-91c0-af34dba1cd79\",\"processDetailRedisKey\":\"activity:optimize:process:detail:c59f06d2-e7e8-4a06-91c0-af34dba1cd79\"},{\"nextRedisKey\":\"activity:optimize:next:7770128b-e32c-ec11-b6e6-00224858a8e5cbb04648-3652-4b9f-8487-44a41f4c8e5d\",\"processRedisKey\":\"activity:optimize:process:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"firstRedisKeyLock\":\"activity:optimize:first:lock:100000002\",\"typeIndex\":1,\"nextRedisLock\":\"activity:optimize:next:lock:7770128b-e32c-ec11-b6e6-00224858a8e5cbb04648-3652-4b9f-8487-44a41f4c8e5d\",\"processDetailRedisKeyLock\":\"activity:optimize:process:detail:lock:cbb04648-3652-4b9f-8487-44a41f4c8e5d\",\"type\":100000002,\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"prevNode\":\"0ecffbb6-71f8-4412-8207-19042bfed4f5\",\"firstRedisKey\":\"activity:optimize:first:100000002\",\"nextNode\":\"f5923792-24eb-42c0-9e07-3bf05cd88db5\",\"name\":\"用户\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5cbb04648-3652-4b9f-8487-44a41f4c8e5d\",\"id\":\"cbb04648-3652-4b9f-8487-44a41f4c8e5d\",\"processDetailRedisKey\":\"activity:optimize:process:detail:cbb04648-3652-4b9f-8487-44a41f4c8e5d\"}],\"activityId\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"marketingActivityRuleMap\":{\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5cbb04648-3652-4b9f-8487-44a41f4c8e5d100000002\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"customerGroupId\\\":\\\"2df4fa5c-0811-ec11-b6e6-000d3ac7f5af\\\",\\\"groupType\\\":100000001,\\\"id\\\":\\\"17278da9-772e-4c96-95f3-8d5a3f64537e\\\",\\\"processId\\\":\\\"cbb04648-3652-4b9f-8487-44a41f4c8e5d\\\"}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e54135bd86-56da-4856-918c-0dba2548b034100000008\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"baseTemplateId\\\":\\\"0c8963b7-7005-ec11-b6e6-000d3aa2ef3b\\\",\\\"id\\\":\\\"0b4ed4f5-6afc-4fb2-b166-a88db39f8512\\\",\\\"msgSendType\\\":\\\"CAMPAIGN_MSGTYPE_SMS\\\",\\\"processId\\\":\\\"4135bd86-56da-4856-918c-0dba2548b034\\\",\\\"sendType\\\":100000000,\\\"type\\\":100000000}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e505a87492-be98-456a-a1c6-b7df001ca595100000004\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"childList\\\":[{\\\"processId\\\":\\\"e774b0bc-078f-4ba2-abab-03afa8317d7c\\\",\\\"processType\\\":100000005}],\\\"firstChild\\\":{\\\"$ref\\\":\\\"$.childList[0]\\\"},\\\"id\\\":\\\"39289089-dc3a-4442-97e3-875353fb708d\\\",\\\"probability\\\":14.0,\\\"processId\\\":\\\"05a87492-be98-456a-a1c6-b7df001ca595\\\"}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5db9e9465-4824-4b75-b65c-408d40064efb100000004\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"childList\\\":[{\\\"processId\\\":\\\"c59f06d2-e7e8-4a06-91c0-af34dba1cd79\\\",\\\"processType\\\":100000005}],\\\"firstChild\\\":{\\\"$ref\\\":\\\"$.childList[0]\\\"},\\\"id\\\":\\\"59d04bcf-9355-4d75-99bf-3b56718289e0\\\",\\\"probability\\\":72.0,\\\"processId\\\":\\\"db9e9465-4824-4b75-b65c-408d40064efb\\\"}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e556608636-a5c5-42e5-b15e-47e38b0cd7be100000006\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"couponPublishCount\\\":1,\\\"couponRuleId\\\":\\\"459b0992-5405-ec11-b6e6-000d3aa2ef3b\\\",\\\"id\\\":\\\"f5c644fb-47c2-422b-9f32-d71a85bae744\\\",\\\"processId\\\":\\\"56608636-a5c5-42e5-b15e-47e38b0cd7be\\\",\\\"type\\\":100000001}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5c59f06d2-e7e8-4a06-91c0-af34dba1cd79100000005\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"behaviorAttribute\\\":\\\"{\\\\\\\"firstLogicalVal\\\\\\\":0,\\\\\\\"firstCondition\\\\\\\":[{\\\\\\\"secondCondition\\\\\\\":[],\\\\\\\"secondLogicalVal\\\\\\\":0}]}\\\",\\\"customerBehavior\\\":100000000,\\\"eventName\\\":\\\"支付事件\\\",\\\"eventType\\\":\\\"$payment\\\",\\\"id\\\":\\\"54faec4e-21ed-4d36-a29a-7d3cf7d05af7\\\",\\\"measureProperty\\\":\\\"{}\\\",\\\"processId\\\":\\\"c59f06d2-e7e8-4a06-91c0-af34dba1cd79\\\",\\\"timeCondition\\\":\\\"{\\\\\\\"beginTime\\\\\\\":\\\\\\\"2021-10-14 00:00:00\\\\\\\",\\\\\\\"endTime\\\\\\\":\\\\\\\"2021-10-16 23:59:59\\\\\\\"}\\\",\\\"timeType\\\":100000000}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5f5923792-24eb-42c0-9e07-3bf05cd88db5100000005\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"behaviorAttribute\\\":\\\"{\\\\\\\"firstLogicalVal\\\\\\\":0,\\\\\\\"firstCondition\\\\\\\":[{\\\\\\\"secondCondition\\\\\\\":[],\\\\\\\"secondLogicalVal\\\\\\\":0}]}\\\",\\\"customerBehavior\\\":100000000,\\\"eventName\\\":\\\"交易事件\\\",\\\"eventType\\\":\\\"$order\\\",\\\"id\\\":\\\"eb8802b6-905c-4000-9e5f-98fa2e92c0a5\\\",\\\"measureProperty\\\":\\\"{}\\\",\\\"processId\\\":\\\"f5923792-24eb-42c0-9e07-3bf05cd88db5\\\",\\\"timeCondition\\\":\\\"{\\\\\\\"beginTime\\\\\\\":\\\\\\\"2021-10-14 00:00:00\\\\\\\",\\\\\\\"endTime\\\\\\\":\\\\\\\"2021-10-16 23:59:59\\\\\\\"}\\\",\\\"timeType\\\":100000000}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5b344117a-fc42-4c76-8891-7c2db5eea563100000006\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"couponPublishCount\\\":1,\\\"couponRuleId\\\":\\\"2b3acb5a-5405-ec11-b6e6-000d3aa2ef3b\\\",\\\"id\\\":\\\"a1fa7e78-3bef-4021-8098-dd648e08a5dd\\\",\\\"processId\\\":\\\"b344117a-fc42-4c76-8891-7c2db5eea563\\\",\\\"type\\\":100000001}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e526f2bfa9-932f-4250-bc75-d9b00e129758100000004\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"childList\\\":[{\\\"processId\\\":\\\"56608636-a5c5-42e5-b15e-47e38b0cd7be\\\",\\\"processType\\\":100000006}],\\\"firstChild\\\":{\\\"$ref\\\":\\\"$.childList[0]\\\"},\\\"id\\\":\\\"ea4dbbb9-e4be-4b55-bd0a-091506d7d2ab\\\",\\\"probability\\\":14.0,\\\"processId\\\":\\\"26f2bfa9-932f-4250-bc75-d9b00e129758\\\"}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5e774b0bc-078f-4ba2-abab-03afa8317d7c100000005\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"behaviorAttribute\\\":\\\"{\\\\\\\"firstLogicalVal\\\\\\\":0,\\\\\\\"firstCondition\\\\\\\":[{\\\\\\\"secondCondition\\\\\\\":[],\\\\\\\"secondLogicalVal\\\\\\\":0}]}\\\",\\\"customerBehavior\\\":100000000,\\\"eventName\\\":\\\"支付事件\\\",\\\"eventType\\\":\\\"$payment\\\",\\\"id\\\":\\\"431dddbc-dd2a-4253-80f8-d0b0718c340d\\\",\\\"measureProperty\\\":\\\"{}\\\",\\\"processId\\\":\\\"e774b0bc-078f-4ba2-abab-03afa8317d7c\\\",\\\"timeCondition\\\":\\\"{\\\\\\\"beginTime\\\\\\\":\\\\\\\"2021-10-14 00:00:00\\\\\\\",\\\\\\\"endTime\\\\\\\":\\\\\\\"2021-10-16 23:59:59\\\\\\\"}\\\",\\\"timeType\\\":100000000}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e55567feb6-1f88-4302-b658-82fa52c2dd86100000007\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"id\\\":\\\"f583c035-f6ce-4aac-b01b-8c6209fbef20\\\",\\\"processId\\\":\\\"5567feb6-1f88-4302-b658-82fa52c2dd86\\\",\\\"type\\\":100000000,\\\"unit\\\":100000004,\\\"waitDuration\\\":1}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5218e7c92-3e37-46db-907a-443d4a58d9eb100000006\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"couponPublishCount\\\":1,\\\"id\\\":\\\"6ac0078f-2cf3-4dce-a3ea-81e1c50de380\\\",\\\"integrationPeriod\\\":\\\"{\\\\\\\"unit\\\\\\\":100000000,\\\\\\\"count\\\\\\\":1}\\\",\\\"joinUpgrade\\\":100000000,\\\"pointGroupId\\\":\\\"c3fde0c5-5199-eb11-b1ac-0022485639a1\\\",\\\"pointInvalidType\\\":100000000,\\\"pointNum\\\":1.0,\\\"processId\\\":\\\"218e7c92-3e37-46db-907a-443d4a58d9eb\\\",\\\"type\\\":100000000}\",\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5a233638d-0b1c-457e-8e21-4ffd6fdbd8c2100000008\":\"{\\\"activityId\\\":\\\"7770128b-e32c-ec11-b6e6-00224858a8e5\\\",\\\"baseTemplateId\\\":\\\"b5443d29-0d06-ec11-b6e6-000d3aa2ef3b\\\",\\\"id\\\":\\\"7e9ff971-6bd9-4585-bad5-b61db18af8f9\\\",\\\"msgSendType\\\":\\\"CAMPAIGN_MSGTYPE_SMS\\\",\\\"processId\\\":\\\"a233638d-0b1c-457e-8e21-4ffd6fdbd8c2\\\",\\\"sendType\\\":100000000,\\\"type\\\":100000000}\"},\"tenantId\":\"techsunst\",\"marketingActivity\":{\"loyaltyId\":\"7025a83c-312b-ec11-b6e6-00224858a3c1\",\"code\":\"HD2110140003\",\"periodRedisKey\":\"activity:optimize:period:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"sourceCode\":\"100000000,100000001,100000002,100000003\",\"redisKey\":\"activity:optimize:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"beginTime\":1634140800000,\"id\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"redisLock\":\"activity:optimize:lock:7770128b-e32c-ec11-b6e6-00224858a8e5\",\"typeCode\":100000001,\"name\":\"测试3\",\"auditStatus\":100000002,\"endTime\":1634399999000,\"activityType\":0,\"status\":100000001}}\n"
    //      initActivity(json)

    val value = "{\"id\":\"7770128b-e32c-ec11-b6e6-00224858a8e5\",\"status\":100000002}"
    val map = JSON.parseObject(value, classOf[util.Map[String, AnyRef]])
    println(map)
    val activity_id = map.get("id").toString
    println(activity_id)
    if (value.contains("\"status\":100000002")) {
      println("1111")
    }
    //      msgProcess(json)

  }

  def msgProcess(value: String): Unit = {

    if (value.contains("marketingActivity")) {
      initActivity(value)
    } else {
      updateActivity(value)
      //      if (value.contains("\"status\":100000002")) {
      //        val map = JSON.parseObject(value, classOf[util.Map[String, AnyRef]])
      //        val activity_id = map.get("id").toString
      //        InitializeGroupActivity4D365.start(activity_id)
      //      }
    }

  }

  /**
   * 初始化活动规则详情数据
   *
   * @param json
   * @throws KuduException
   */
  @throws[KuduException]
  def initActivity(json: String): Unit = {
    val kuduClient = new KuduClient.KuduClientBuilder(ApplicationConfig.KUDU_MASTER).build
    val kuduSession = kuduClient.newSession
    val tsrMarketingActivity = kuduClient.openTable("tsr_marketing_activity")
    val tsrMarketingActivityProcess = kuduClient.openTable("tsr_marketing_activity_process")
    val tsrMarketingProcessBehavior = kuduClient.openTable("tsr_marketing_process_behavior")
    val tsrMarketingProcessCustomer = kuduClient.openTable("tsr_marketing_process_customer")
    val tsrMarketingProcessTest = kuduClient.openTable("tsr_marketing_process_test")
    val tsrMarketingProcessWait = kuduClient.openTable("tsr_marketing_process_wait")
    val schema = tsrMarketingActivity.getSchema
    System.out.println(schema.getColumns)
    //向kudu写入活动表数据
    val marketingActivity = getValue(json, "marketingActivity")
    msg2Kudu(tsrMarketingActivity, marketingActivity, kuduSession)
    val marketingActivityProcessList = getValue(json, "marketingActivityProcessList")
    println(marketingActivityProcessList)
    val list = JSON.parseObject(marketingActivityProcessList, classOf[Array[String]])

    for (i <- list) { //向kudu写入节点表数据
      msg2Kudu(tsrMarketingActivityProcess, i, kuduSession)
    }
    val marketingActivityRuleMap = getValue(json, "marketingActivityRuleMap")
    val hashMap = JSON.parseObject(marketingActivityRuleMap, classOf[util.HashMap[_, _]])
    import scala.collection.JavaConversions._
    for (key <- hashMap.keySet) {
      if (key.toString.endsWith("100000002")) { //客户表
        msg2Kudu(tsrMarketingProcessCustomer, hashMap.get(key).toString, kuduSession)
      }
      else if (key.toString.endsWith("100000004")) { //A/B test表
        msg2Kudu(tsrMarketingProcessTest, hashMap.get(key).toString, kuduSession)
      }
      else if (key.toString.endsWith("100000005")) { //行为表
        msg2Kudu(tsrMarketingProcessBehavior, hashMap.get(key).toString, kuduSession)
      }
      else if (key.toString.endsWith("100000007")) { //等待表
        msg2Kudu(tsrMarketingProcessWait, hashMap.get(key).toString, kuduSession)
      }
    }
  }

  /**
   * 更新活动状态
   *
   * @param json json格式的字符串，包含活动id和状态
   * @throws KuduException
   */
  @throws[KuduException]
  def updateActivity(json: String): Unit = {
    val kuduClient = new KuduClient.KuduClientBuilder(ApplicationConfig.KUDU_MASTER).build
    val kuduSession = kuduClient.newSession
    val tsrMarketingActivity = kuduClient.openTable("tsr_marketing_activity")
    msg2Kudu(tsrMarketingActivity, json, kuduSession)
  }

  /**
   * 将字符串中的大写字母改为下划线加小写字母
   *
   * @param param eg:aBcD
   * @return eg:a_bc_d
   */
  def camel4underline(param: String): String = {
    val p = Pattern.compile("[A-Z]")
    if (param == null || param == "") return ""
    val builder = new StringBuilder(param)
    val mc = p.matcher(param)
    var i = 0
    while ( {
      mc.find
    }) {
      builder.replace(mc.start + i, mc.end + i, "_" + mc.group.toLowerCase)
      i += 1
    }
    if ('_' == builder.charAt(0)) builder.deleteCharAt(0)
    builder.toString
  }

  def getValue(json: String, key: String): String = {
    val map = JSON.parseObject(json, classOf[util.HashMap[_, _]])
    val result = map.get(key).toString
    result
  }

  /**
   * 将消息写入kudu
   *
   * @param table kudu表
   * @param json
   * @param session
   * @throws KuduException
   */
  @throws[KuduException]
  def msg2Kudu(table: KuduTable, json: String, session: KuduSession): Unit = {
    val map = JSON.parseObject(json, classOf[util.HashMap[String, AnyRef]])
    val schemaMap = getSchemaMap(table)
    val upsert = upsertRow(table, map, schemaMap)
    session.apply(upsert)
    session.flush
  }

  /**
   * 根据kudu表实体获取Schema
   *
   * @param table kudu表
   * @return kudu Schema map（列名 -> 字段类型）
   */
  def getSchemaMap(table: KuduTable): util.HashMap[String, String] = {
    val map = new util.HashMap[String, String]
    val schema = table.getSchema
    import scala.collection.JavaConversions._
    for (next <- schema.getColumns) {
      val name = next.getName
      val `type` = next.getType.getName
      map.put(name, `type`)
    }
    map
  }

  /**
   * 获取需要更新的Kudu Upsert的条件
   *
   * @param table     kudu表
   * @param map       map（列名 -> 属性值）
   * @param schemaMap kudu Schema map（列名 -> 字段类型）
   * @return Upsert
   */
  def upsertRow(table: KuduTable, map: util.HashMap[String, AnyRef], schemaMap: util.HashMap[String, String]): Upsert = {
    val upsert = table.newUpsert
    val row = upsert.getRow
    import scala.collection.JavaConversions._
    for (key <- map.keySet) {
      val kuduKey = camel4underline(key)
      if (schemaMap.containsKey(kuduKey)) {
        val `type` = schemaMap.get(kuduKey)
        val value = map.get(key)
        row.addString("project", ApplicationConfig.PROJECT)
        row.addLong("create_time", System.currentTimeMillis * 1000)
        row.addLong("update_time", System.currentTimeMillis * 1000)
        `type` match {
          case "string" =>
            row.addString(kuduKey, value.toString)
          case "unixtime_micros" =>
            row.addLong(kuduKey, value.toString.toLong * 1000)
          case "double" =>
            row.addDouble(kuduKey, value.toString.toDouble)
          case "int32" =>
            row.addInt(kuduKey, value.toString.toInt)
          case "int64" =>
            if (key == "probability") {
              row.addLong(kuduKey, value.toString.toDouble.floor.toLong)
            }
            else row.addLong(kuduKey, value.toString.toLong)

        }
      }
    }
    upsert
  }

}
